package cn.huxingyuan.service.impl;

import cn.huxingyuan.user.domain.User;
import cn.huxingyuan.mapper.UserMapper;
import cn.huxingyuan.user.query.UserQuery;
import cn.huxingyuan.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Hu
 * 2025/8/5 16:11
 */
@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findById(Long id) {
        return userMapper.findById(id);
    }

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public void add(User user) {
        userMapper.add(user);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void deleteById(Long id){
        userMapper.deleteById(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        userMapper.batchDelete(ids);
    }

    @Override
    public PageInfo<User> pageAll(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPage(), userQuery.getSize());
        List<User> pageInfo = userMapper.pageAll(userQuery);
       return new PageInfo<>(pageInfo);
    }
}
